//package com.ruoyi.user.model.factory.impl;
//
//import com.mmd.base.auth.TokenTemplate;
//import com.mmd.base.pojo.entity.UserInfo;
//import com.mmd.base.pojo.vo.TokenVO;
//import com.mmd.tencent.util.TencentCloudImUtil;
//import com.mmd.user.model.enums.LoginStrategy;
//import com.mmd.user.model.pojo.entity.User;
//import com.mmd.user.model.pojo.request.LoginRequest;
//import com.mmd.user.services.factory.LoginFactory;
//import com.mmd.user.services.service.IUserService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.util.Assert;
//import org.springframework.util.StringUtils;
//
//@Component
//public class LoginFactoryPhoneImpl implements LoginFactory {
//    @Autowired
//    private IUserService iUserService;
//    @Autowired
//    private TencentCloudImUtil tencentCloudImUtil;
//
//    @Override
//    public TokenVO<String> login(LoginRequest loginRequest) throws Exception {
//        Assert.isTrue(StringUtils.hasText(loginRequest.getToken()),"一键登录的token不能为空");
//        //解析一键登录的token值拿到手机号 手机号登录
//        String phone = iUserService.verifyTokenGetPhone(loginRequest.getToken());
//        User one = iUserService.loginVerify(phone);
//        UserInfo<String> userInfo = UserInfo.<String>builder()
//                .username(one.getPhone())
//                .userId(one.getId())
//                .phone(one.getPhone())
//                .build();
//        String authorization = TokenTemplate.saveToken(loginRequest.getLoginEnum(), userInfo);
//        return TokenVO.<String>builder()
//                .authorization(authorization)
//                .loginEnum(loginRequest.getLoginEnum())
//                .isAuthentication(one.getIsAuthentication())
//                .imUsername(one.getImUsername())
//                .userSig(tencentCloudImUtil.getTxCloudUserSigAnd(one.getImUsername()))
//                .isNewUser(one.getIsNewUser())
//                .other("手机号一键登录")
//                .build();
//    }
//
//    @Override
//    public LoginStrategy getStrategy() {
//        return LoginStrategy.PHONE;
//    }
//}
